﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTcpSocket>
#include <QUdpSocket>
#include <QTimer>
#include <QFile>
#include <QDir>
#include <QFileDialog>
#include "motion_param.h"
enum
{
    MOTION_INI_ORG = 0x01,     //初始化找原点 定0位
    MOTION_INI_LIMT,           //初始化找终点  定最大长度
    MOTION_SET_PARAM,          //设置运动参数
    MOTION_SET_COOR,           //设置逻辑坐标（运动参数指定坐标类型）
    MOTION_GET_COOR,           //获取逻辑坐标（运动参数指定坐标类型）
    MOTION_GET_PWM_COOR,       //获取PWM坐标
    MOTION_GET_QEP_COOR,       //获取QEP坐标
    MOTION_MOVE_TO,            //定点运动
    MOTION_MOVE_LEN,            //定长运动,
    MOTION_MOVE_TOEX,            //定点运动mm单位
    MOTION_MOVE_LENEX,            //定长运动MM单位,
    MOTION_STOP,                //停止运动,
    MOTION_UPDATE_START,                //升级开始,
    MOTION_UPDATE_DATA,                //升级数据,
    MOTION_UPDATE_END,                //升级结束,
    MOTION_CLEAN,                        //清洗命令
    MOTION_DOWET,                        //保湿命令
    MOTION_OUTWET,                       //退出保湿命令
    MOTION_IS_MOVING,                    //各个轴是否正在运动
    MOTION_IO_GET_IN,                       //输入IO状态
    MOTION_IO_GET_OUT,                       //输出IO状态
    MOTION_IO_SET_OUT,                       //输出IO状态
    MOTION_AXIS_MOVE_FINISH_INFO,           //运动完成信息
    MOTION_GET_SYS_STATUS,                       //获取系统状态
    MOTION_VENDER_CMD,                       //vender一级命令
    MOTION_GET_MOVEINFO,                        //获取运动曲线信息
    MOTION_GET_BOARD_INFO,                      //获取板子信息
    MOTION_GET_NET_INFO,                      //获取板子网络信息
};

enum
{
    AXIS1 = 0x00,
    AXIS2,
    AXIS3,
    AXIS4,
    AXIS5,
    AXIS6,
    AXIS7,
    AXIS8,
    AXIS_MAX
};

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
private:
   void sendtocom(char *buf,uint32_t len);
   void sendtoudpcom(char *buf,uint32_t len);
   void motion_req_proc(char *buf,uint32_t len);
private slots:
    void on_ForwordButton_clicked();

    void on_ConnectButton_clicked();

    void connect_slot();

    void readyread_slot();
    void readyreadudp_slot();
    void connect_time_slot();
    void on_stopButton_clicked();

    void on_BackButton_clicked();

    void on_pushFButton_pressed();

    void on_pushFButton_released();

    void on_pushBButton_pressed();

    void on_pushBButton_released();

    void tcp_time_slot();

    void move_time_slot();

//    void on_pushF1Button_pressed();

//    void on_pushF1Button_released();

//    void on_pushB2Button_pressed();

//    void on_pushB2Button_released();

//    void on_F2Button_clicked();

//    void on_B2Button_clicked();

    void on_closeButton_clicked();

    void disconnect_slot();

    void on_movetor1Button_clicked();

    void update_time_slot();

    void on_updateButton_clicked();

    void on_movelenr1Button_clicked();

//    void on_movetor2Button_clicked();

//    void on_movelenr2Button_clicked();

    void on_motionButton_clicked();

    void on_movelenr1Buttonex_clicked();

//    void on_push3FButton_pressed();

//    void on_push3FButton_released();

//    void on_push3BButton_pressed();

//    void on_push3BButton_released();

//    void on_push4FButton_pressed();

//    void on_push4FButton_released();

//    void on_push4BButton_pressed();

//    void on_push4BButton_released();

    void on_pushButton_H_clicked();

    void on_pushButton_L_clicked();

//    void on_movetor3Button_clicked();

//    void on_movetor4Button_clicked();

//    void on_movelenr1Button_2_clicked();

//    void on_movelenr1Button_4_clicked();

//    void on_movelenr2Buttonex_clicked();

//    void on_movelenr3Buttonex_clicked();

//    void on_movelenr4Buttonex_clicked();

    void on_pushBButton_clicked();

    void on_pushFButton_clicked();

    void on_pushButtoncunt_clicked();

    void on_pushButton_clicked();

private:
    Ui::MainWindow *ui;

    QTcpSocket *tcpsocket;
    QUdpSocket *udpsocket;
    QTimer *tcp_timer;
    QTimer *update_timer;
    QTimer *connect_timer;

    QTimer *move_timer;

    int tcp_time_func;
    int move_time_func;

    int update_rcv_flag = 0;
    int update_send_flag = 0;
    QFile *file;

    uint8_t axis_ismoving[8];
    motion_param *_motion_param;
    uint8_t connect_bt = 0;
    uint8_t connect_sta = 0;
};

#endif // MAINWINDOW_H
